import { Component, OnInit } from '@angular/core';
import { Store } from '@ngxs/store';
import { SystemSelector } from '../../store/system/system.selector';
import { SystemAction } from '../../store/system/system.action';
import { AutoUnsubscribe } from 'ngx-auto-unsubscribe-decorator';

@Component({
  selector: 'app-backup',
  templateUrl: './backup.component.html',
  styleUrls: ['./backup.component.scss'],
})
export class BackupComponent implements OnInit {
  list: any = [];
  @AutoUnsubscribe() loading$ = this.store.select(SystemSelector.loading);
  @AutoUnsubscribe() canBackup$ = this.store.select(SystemSelector.canBackup);
  @AutoUnsubscribe() defaultParam$ = this.store.select(SystemSelector.defaultParam);

  constructor(
      private store: Store,
  ) {
    this.store.select(SystemSelector.list).subscribe(r => this.list = r);
  }

  ngOnInit() {
    this.store.dispatch(new SystemAction.LoadBackupList());
  }

  revert(data: any) {
    this.store.dispatch(new SystemAction.Revert(data));
  }

  backup() {
    this.store.dispatch(new SystemAction.Backup());
  }
}
